//==============================================================================
//
// Title:       ScreenRTC.c
// Purpose:     A short description of the implementation.
//
// Created on:  23/09/2010 at 08:37:36 by LEGRAND.
// Copyright:   GRPLEG. All Rights Reserved.
//
//==============================================================================

//==============================================================================
// Include files
#include "Screen_Setup_1.h"


//==============================================================================
// Constants
//==============================================================================
// Types

//==============================================================================
// Static global variables

//==============================================================================
// Static functions
static unsigned char Screen_Setup_1_OnInitialize( void );

static unsigned char Screen_Setup_1_ProcessMessage( TMessage* pMsg );

//==============================================================================
// Global variables


//==============================================================================
// Global functions

const TScreen Screen_Setup_1 =
{
	.ProcessMessage 	= Screen_Setup_1_ProcessMessage,
	.OnInitialize   	= Screen_Setup_1_OnInitialize,
};

static unsigned char Screen_Setup_1_OnInitialize( void )
{
uInt8 tmp = Is_Battery_Present();

 if(GetFlag(FLAG_BATT1_PRESENT))
  {
 LCD_Clear();
 LCD_DrawString("P1:Enter C(mAh)",1,LINE_1);
 LCD_DrawCapacity(EE_Capacity_1,1,LINE_2);
 LCD_DrawChar(' ');
 LCD_DrawChar(ARROW_UP);
 LCD_DrawChar(ARROW_DOWN);
 LCD_DrawString("  ->OK",11,LINE_2);
  }
  else if(GetFlag(FLAG_BATT2_PRESENT))
  {
   Screen_SetCurrent(&Screen_Setup_2);
  }
  else{
   Reset_By_Watchdog();
  }


  return 0U;
}

static unsigned char Screen_Setup_1_ProcessMessage( TMessage* pMsg )
{

  	if( pMsg->ID == MSG_KEY_BOARD )
	{

		switch( pMsg->Param1 )
		{
                                          case KEY_OK:
                                          {

                                            SetFlag(FLAG_DUMMY1);


                                             if(GetFlag(FLAG_BATT2_PRESENT) AND !GetFlag(FLAG_DUMMY2) )
                                                  {
                                                    Screen_SetCurrent(&Screen_Setup_2);
                                                  }
                                             else
                                             {
                                                    Screen_SetCurrent(&Screen_Start_1);
                                             }



                                          }
                                          break;
                                          case KEY_UP:
                                          {
                                                  EE_Capacity_1 = EE_Capacity_1 + CAPACITY_STEP;

                                                  if(EE_Capacity_1 >= MAX_CAPACITY)
                                                  {
                                                            EE_Capacity_1=MAX_CAPACITY;
                                                  }
                                                  LCD_DrawCapacity(EE_Capacity_1,1,LINE_2);

                                          }
                                          break;
                                          case KEY_DOWN:
                                          {
                                                  EE_Capacity_1 = EE_Capacity_1 - CAPACITY_STEP;

                                                  if(EE_Capacity_1 <= MIN_CAPACITY)
                                                  {
                                                            EE_Capacity_1=MIN_CAPACITY;
                                                  }
                                                  LCD_DrawCapacity(EE_Capacity_1,1,LINE_2);
                                          }
                                          break;
                                          case KEY_LEFT:
                                          {

                                          }
                                          break;
                                          case KEY_RIGHT:
                                          {

                                          }
                                          break;
                                }
                }
                else if( pMsg->ID == MSG_TIMER )
                  {
                         //Toggle_Led();
                  }
                  else
                  {

                   }



	return 0U;
}

